<?php 

namespace app\user\controller;
use think\Request;
use think\Session;
use app\common\traits\controller\TraitController;
/**
 * 会员消息类
 */
class Message extends \think\Controller
{
	use TraitController;
	
	public function init(){
		if (!model('Users')->checkLogin()) {
			Session::set('redirect_url', Request::instance()->url(true));
            $this->redirect('@user/login');
            exit;
        }
	}
	/**
	 * 消息列表
	 */
	public function getIndex(){
		$msgAll = model('UserMessages')->msgNum(null,self::getLoginUserInfo('id'));
		$msgNotRead = model('UserMessages')->msgNum(0,self::getLoginUserInfo('id'));
		$list = model('UserMessages')->getMsgList(self::getLoginUserInfo('id'));
		//$list = collection($list);
		return view('user_message/index',['list' => $list,'msgAll'=>$msgAll,'msgNotRead'=>$msgNotRead]);
	}
	
	/**
	 * 删除消息
	 */
	public function getDel(){
		if(model('UserMessages')->delMsg(input('get.id'))){
			$this->success(lang('delete message success'),'/message/index');
		}
		$this->error(lang('delete message error'));
	}
	
	/**
	 * 设置消息状态
	 */
	public function postSetStatus(){
		if(model('UserMessages')->getMsg(input('post.id'),self::getLoginUserInfo('id'))){
			return json(true);
		}
		return json(false);
	}
}


 ?>